<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <h2>{{formatHour}}时{{formatMin}}分{{formatSec}}秒</h2>
    <h2>{{formatHour}}时{{formatMin}}分{{formatSec}}秒</h2>
  </div>
  <script src="./vue.js"></script>
  <script>
    new Vue({
      el: "#app",
      data: {
        hour: 0,
        min: 0,
        sec: 0
      },
      computed:{
        formatHour(){
          return this.addZero(this.hour);
        },
        formatMin(){
          return this.addZero(this.min);
        },
        formatSec(){
          return this.addZero(this.sec);
        }
      },
      mounted(){
        let time = new Date();
        this.hour = time.getHours();
        this.min = time.getMinutes();
        this.sec = time.getSeconds();
        setInterval(this.next,1000);
      },
      methods: {
        addZero(t) {
          var temp = t + "";
          if (t < 10) {
            temp = "0" + t;
          }
          return temp;
        },
        next() {
          if (this.sec == 59) {
            this.sec = 0;
            this.min++;
            if (this.min == 59) {
              this.min = 0;
              this.hou++;
              if (this.hour == 23) {
                this.hour = 0;
              }
            }
          } else {
            this.sec++;
          }
        }
      }
    });
  </script>
</body>

</html>